package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseCellInfo;
import com.softer.wxzj.entity.BaseCellInfoList;
import com.softer.wxzj.service.BaseCellInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * BaseBuildInfoController class
 *
 * @author zcz
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/baseCellInfo")
@Slf4j
public class BaseCellInfoController {
    @Autowired
    BaseCellInfoService baseCellInfoService;

    /**
     * 单元添加或修改
     * @param baseCellInfoList 参数集合
     * @return 处理结果
     */
    @PostMapping("/insertOrUpdate")
    @LogRecord(description = "单元添加或修改",operationUnit = LogOperationUnit.BASE_CELL_INFO,operationType = LogOperationType.REPLACE)
    public CommonResult insertOrUpdate(@RequestBody List<BaseCellInfo> baseCellInfoList) {
        return baseCellInfoService.insertOrUpdate(baseCellInfoList);
    }

    /**
     * 删除单元同时删除对应房屋
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @LogRecord(description = "单元信息删除", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.DELETE)
    public CommonResult delete(@RequestParam("id") String id) {
        return baseCellInfoService.delete(id);
    }

    /**
     * 查询列表
     * @param baseCellInfo
     * @return
     */
    @PostMapping("/getAllList")
    @LogRecord(description = "查询所有列表", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseCellInfo> getAllList(Page page, BaseCellInfo baseCellInfo){
        return baseCellInfoService.getAllList(page,baseCellInfo);
    }

    /**
     * 查询列表，不分页
     * @param baseCellInfo
     * @return
     */
    @PostMapping("/getAllListAndDetail")
    @LogRecord(description = "查询所有列表", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseCellInfo> getAllListAndDetail(Page page, BaseCellInfo baseCellInfo){
        return baseCellInfoService.getAllListAndDetail(page,baseCellInfo);
    }

    /**
     * 查询列表，不分页
     * @param baseCellInfo
     * @return
     */
    @PostMapping("/getList")
    @LogRecord(description = "查询所有列表，不分页", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    public List<BaseCellInfo>  getList(BaseCellInfo baseCellInfo){
        return baseCellInfoService.getList(baseCellInfo);
    }

    /**
     * 根据自然懂编号查询单元列表   用来填充下拉框
     * @param buildNo
     * @return
     */
    @PostMapping("/getCellListByBuildNo")
    public List<Map<String,String>> getCellListByBuildNoAndCellType(@RequestParam("buildNo") String buildNo) {
        return baseCellInfoService.getCellListByBuildNo(buildNo);
    }

    /**
     * 查询列表，不分页
     * @param buildNo
     * @return
     */
    @RequestMapping("/getListInfo")
    @LogRecord(description = "查询单个楼幢的单元", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    public List<BaseCellInfoList> getListInfo(String buildNo) {
        return baseCellInfoService.getListInfo(buildNo);
    }
    /**
     * 查询列表，不分页
     * @param baseCellInfo
     * @return
     */
    @RequestMapping("/updateToSave")
    @LogRecord(description = "变更单元结构", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    public CommonResult updateToSave(@RequestBody List<BaseCellInfo> baseCellInfo)throws Exception {
        return baseCellInfoService.updateToSave(baseCellInfo);
    }

    /**
     * 变更单元结构查询
     * @param buildNo
     *  @param reqNo
     * @return
     */
    @RequestMapping("/getListInfoUpdate")
    @LogRecord(description = "变更单元结构查询", operationUnit = LogOperationUnit.BASE_CELL_INFO, operationType = LogOperationType.SELECT)
    List<BaseCellInfoList> getListInfoUpdate(String buildNo,String reqNo) {
    return baseCellInfoService.getListInfoUpdate(buildNo,reqNo);
    }


}
